package edu.ahut.corejava;


public class JoinNumbers4 {//O(log(n))

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        long n = 999999999999L;
        //long n=100009;
        //1- 9   9个1位数
        //10-99 90个2位数
        //...
        //10^(k-1)- (10^k-1) 9*(10^(k-1))个k位数

        ///488949
        long s = 0;
        long t = 9, w = 1;
        while (t <= n) {
            s += w * t;
            t = t * 10;
            w++;
        }
        s += (n + 1 - Math.pow(10, w - 1)) * w;
        System.out.println(s);
        long end = System.currentTimeMillis();
        System.out.println((end - start) / 1000.0 + " second(s).");
    }
}
/**
 * 1-n   n=9 ,99,999,9999
 * 1 2 3 4 5 6 7 8 9  (1*10)
 * 10                         99 (2*90)
 * 100 --999  (3*900)
 * <p>
 * 1-1024
 * <p>
 * 1- 9   10
 * 10-99   180
 * 100-999  270
 * 1000-1024 (24+1)*4
 */